package com.xiaolun.other;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class Demo05 {
	public static void main(String[] args) {
		fileInputStreamDemo();
	}

	private static void fileInputStreamDemo() {
		String separator = File.separator;
		//1、定义要进行磁盘输出的完整路径
		File file = new File("D:" + separator + "test" + separator + "test3.txt");
		if (file.exists()) {
			FileInputStream input = null;
			try {
				//实例化输入流对象
				input = new FileInputStream(file);
				//开辟一个空间进行数据读取
				byte[] data = new byte[1024];
				//将输入流的内容读取到字节数组之中
				int length = input.read(data);
				System.out.println("length --->" + length); //11
				System.out.println(new String(data,0,length));
			} catch (Exception e) {
				e.printStackTrace();
			}finally {
				try {
					input.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
}
